package com.gm.wholesale.module.good.bean;
import com.gm.wholesale.module.unit.bean.UnitBean;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class GoodListBean implements Serializable {

    @SerializedName("id")
    public long id;
    @SerializedName("name")
    public String name;
    @SerializedName("type")
    public int type;
    @SerializedName("units")
    public List<UnitsBean> units;
    @SerializedName("version")
    public int version;
    @SerializedName("onShelf")
    public boolean onShelf;

    public int handleType;

    public int getHandleType() {
        return handleType;
    }

    public void setHandleType(int handleType) {
        this.handleType = handleType;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public List<UnitsBean> getUnits() {
        return units;
    }

    public void setUnits(List<UnitsBean> units) {
        this.units = units;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public boolean isOnShelf() {
        return onShelf;
    }

    public void setOnShelf(boolean onShelf) {
        this.onShelf = onShelf;
    }

    public static class UnitsBean implements Serializable {
        @SerializedName("id")
        private long id;
        @SerializedName("name")
        private String name;
        @SerializedName("ratio")
        private String ratio;
        @SerializedName("price")
        private String price;
        @SerializedName("type")
        private int type;

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getRatio() {
            return ratio;
        }

        public void setRatio(String ratio) {
            this.ratio = ratio;
        }

        public String getPrice() {
            return price;
        }

        public void setPrice(String price) {
            this.price = price;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public UnitBean getUnitBean() {
            UnitBean unitBean = new UnitBean();
            unitBean.setPrice(price);
            unitBean.setId(id);
            unitBean.setProportionNum(getRatio());
            unitBean.setName(getName());
            unitBean.setType(type);

            return unitBean;
        }
    }

    public List<UnitBean> getUnitData() {
        List<UnitBean> unitBeans=new ArrayList<>();
        if (getUnits()!=null){
            for (UnitsBean unitsBean:getUnits()){
               UnitBean unitBean2=new UnitBean();
                unitBean2.setId(unitsBean.getId());
                unitBean2.setName(unitsBean.getName());
                unitBean2.setType(unitsBean.getType());
                unitBean2.setPrice(unitsBean.getPrice());
               unitBeans.add(unitBean2);
            }
        }
        return unitBeans;
    }
}
